#  控件相关参考资料
#https://blog.csdn.net/mingshao104/article/details/79591965

import tkinter
import fileutil.myfileutil
import fileutil.showTxtInfoToText
import view.mytreeview
import view.MainView as v
import view.myText
import fileutil.outputFileInfo
from tkinter import messagebox
import view.command_file


def mainUI():
    window = v.create_main_view()
    # 获取文件数据
    divt1 = fileutil.myfileutil.get_all_file('D:\百度云同步盘\同步数据\文档')# D:\百度云同步盘\同步数据\文档
    # 创建文件树
    tree = view.mytreeview.create_treeview(divt1, window)
    global file

    def treeview_click(event):  # 单击
        global file
        # print('单击')
        for item in tree.selection():
            item_text = tree.item(item, "values")

            # print(item_text)#输出所选行的第一列的值
            file = item_text
            fileutil.showTxtInfoToText.show_str(item_text, text)

    tree.bind('<ButtonRelease-1>', treeview_click)
    tree.pack(side=tkinter.LEFT, fill=tkinter.Y)

    myFrame = tkinter.Frame(window)
    myFrame.pack( fill=tkinter.BOTH)

#
    def change_file_content():
        var = text.get('0.0', 'end')
        print(var+'--')
        if len(var) > 0:
            # messagebox.showinfo('info', message=var)
            fileutil.outputFileInfo.output_info(file, var)

    button = tkinter.Button(myFrame, text='添加/修改内容', command=lambda: change_file_content())
    button.pack(side=tkinter.TOP, fill=tkinter.X)
    # 显示多行文本
    text = tkinter.Text(myFrame)
    text.pack(fill=tkinter.BOTH, expand=tkinter.YES)

    def open_comm():
        if len(file[0]) > 0:
            view.command_file.comm_file(file[0])
    # 操作文件
    button = tkinter.Button(window, text='操作文件', command=lambda: open_comm())
    button.pack(side=tkinter.TOP, fill=tkinter.X)

    window.mainloop()


if __name__ == '__main__':
    mainUI()
